#include "MzType2Mime.h"

// init
MzType2Mime::MzType2Mime(){
	this->mime = NULL;

	this->dict.emplace(".html", "text/html");
	this->dict.emplace(".txt", "text/plain");
	this->dict.emplace(".js", "application/javascript");
	this->dict.emplace(".css", "text/css");
	this->dict.emplace(".jpg", "image/jpeg");
	this->dict.emplace(".jpeg", "image/jpeg");
	this->dict.emplace(".gif", "image/gif");
	this->dict.emplace(".png", "image/png");
}

MzType2Mime::~MzType2Mime(){
	// free str
	if (this->mime != NULL){
		// printf(" > @MzType2Mime::~MzType2Mime : free mime: %p \n", this->mime);
		free(mime);
	}
}


// use only once before free
char* MzType2Mime::get(char* ftype){
	std::map<std::string, std::string>::iterator it = this->dict.find(ftype);
	std::string _mime;
	if(it != this->dict.end()){
        _mime = it->second;
        // printf(" > @MzType2Mime::get : %s \n", _mime.c_str());
        this->mime = (char*)malloc(_mime.size()+1);
		strcpy(this->mime, _mime.c_str());
		return this->mime;
	}else{
		// printf("not found \n");	
		return NULL;
	}
}

